package com.yonyou.brigade.third_parties.ctrip.groupmembers.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.pojo.CtripGroupMembers;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.pojo.CtripGroupMemberExt;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.dao.CtripGroupMemberMapper ;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.service.ICtripGroupMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangzhf@yonyou.com
 * @since 2018-05-03
 */
@Service(value = "ctripGroupMemberServiceImpl")
public class CtripGroupMemberServiceImpl extends ServiceImpl<CtripGroupMemberMapper, CtripGroupMembers> implements ICtripGroupMemberService {


    @Autowired
    private CtripGroupMemberMapper groupMemberMapper;

    @Override
    public String invokeMethod(String methodName, Map param) {
        switch (methodName){
            case "findGroupMembersByFilter":
            case "getGroupMembersByUserids":
            case "updateNote":
            case "updateGid":
            case "deleteguid":
        }

        return null;
    }

    public Map findGroupMembersByFilter(int groupid, int pageSize, int current, String condition , String tenantid)
    {
        if(current<=0)
        {
            current=1;
        }
        Map result=new HashMap();
        int start=(current-1)*pageSize;
        int size=pageSize;
        try {
            Map params=new HashMap();
            params.put("start",start);
            params.put("size",size);
            params.put("groupid",groupid);
            params.put("condition",condition);
            int total=groupMemberMapper.getGroupMembersByFilterCount(params);
            List<CtripGroupMemberExt> groupMembers=groupMemberMapper.getGroupMembersByFilter(params);
            result.put("code","0");
            result.put("information",groupMembers);
            JSONObject pagination=new JSONObject();
            pagination.put("total",total);
            pagination.put("pageSize",pageSize);
            pagination.put("current",current);
            result.put("pagination",pagination);
        }
        catch (Exception e)
        {
            result.put("code","1");
            result.put("information","操作失败");
        }
        return  result;
    }

    public  List<CtripGroupMemberExt> getGroupMembersByUserids(Map params)
    {
        return groupMemberMapper.getGroupMembersByUserids(params);
    }

    public  Map updateNote(String userid,String note , String tenantid)
    {
        Map result=new HashMap();
        try {
            Map params=new HashMap();
            params.put("userid",userid);
            params.put("note",note);
            groupMemberMapper.updateNote(params);
            result.put("code","0");
            result.put("information","操作成功");
        }
        catch (Exception e)
        {
            result.put("code","1");
            result.put("information","操作失败");
        }
        return result;
    }


    public Map updateGid(String gid,List<String> userids)
    {
        Map result=new HashMap();
        try {
            Map params=new HashMap();
            params.put("gid",gid);
            params.put("list",userids);

            groupMemberMapper.updateGid(params);
            result.put("code","0");
            result.put("information","操作成功");
        }
        catch (Exception e)
        {
            result.put("code","1");
            result.put("information","操作失败");
        }
        return result;
    }

    public Map deleteguid(String gid,List<String> userids)
    {
        Map result=new HashMap();
        try {
            Map params=new HashMap();
            params.put("gid",gid);
            params.put("list",userids);

            groupMemberMapper.deleteguid(params);
            result.put("code","0");
            result.put("information","操作成功");
        }
        catch (Exception e)
        {
            result.put("code","1");
            result.put("information","操作失败");
        }
        return result;
    }
}
